import { View, Text } from '@tarojs/components'
import { useLoad,useDidShow } from '@tarojs/taro'
import './index.scss'
import { AtAvatar } from 'taro-ui';
import { AtCountdown ,AtNoticebar } from 'taro-ui'
import Request from './../../utils/request'
import { useEffect,useState } from 'react';

import moment from 'moment'
import request  from '../../utils/request'
import Taro from '@tarojs/taro'
export default function Index () {
  const [list,setList] = useState([]);
   const [userInfo,setUserInfo] = useState({nickname:''});
  useDidShow(() => {
    console.log('Page loaded.');
    getUserInfo();
  })
   const getUserInfo = ()=>{
    //admin/login
    request.get('app/get-login-user-info').then((res)=>{
      console.log(res);
      setUserInfo(res);
     
      Taro.setStorage({
          key:"userInfo",
          data:res
      })
      window.localStorage.setItem('userInfo',res)
    })
  }
  useEffect(()=>{
    if(userInfo.id){
       getList();
    }
  },[userInfo])
  useLoad(() => {
    console.log('Page loaded.')
  })
   const getList = ()=>{
    //admin/login
    request.post('app/b/seat/occupy/getBookingList', {
            pageNum: 1,
            pageSize: 22222222,
            studentId: userInfo.id
          }).then((res)=>{
      console.log(res);
      setList(res.data||[] );
    })
  }
  return (
    <div className='index-page'>
      {
        list.map((item,index)=>{
          return <div key={index} onClick={()=>{
             Taro.navigateTo({url:'/pages/kcdetail/index?id='+item.id})
          }} className="course-item">
            <div className="course-title">{item.scheduleDTO.courseName}</div>
            <div className="course-sub-title">教师：{item.scheduleDTO.teacherName}</div>
            <div className="course-brief">课程：{item.scheduleDTO.lessonName}</div>
            <div className="course-brief">教室：{item.scheduleDTO.roomName}</div>
<div className="course-brief">座位：{item.seatId}</div>
            
            <div className="course-time">{moment(item.scheduleDTO.startAt).format('YYYY-MM-DD HH:mm')} - {moment(item.scheduleDTO.endAt).format('YYYY-MM-DD HH:mm')}</div>

            {/* 0取消  1已预约  2已结束 */}
            <div className="course-status">状态：{item.status==10?'已预约':(item.status==20?'已取消':'已结课')}</div>
          </div>
        })
      }
    </div>
  )
}
